<?php

namespace app\admin\dao;

use app\common\model\ConsultingServer;
use ShidianUtil\Thinkphp\Dao\DaoTrait;
use think\Collection;

/**
 * ConsultingServerDao 数据访问对象
 * Class MemberAskServerDao
 * @package app\dao
 * @method ConsultingServer findByPK(?int $id, $field = true)
 * @method \think\Collection selectAll(?int $page, ?int $page_size, $field = true)
 * @method ConsultingServer insertActive(array $params, array $allow_field = [])
 * @method ConsultingServer updateActive(ConsultingServer $model, array $params, array $allow_field = [])
 * @method ConsultingServer findAndUpdateActive(int $id, array $params, array $allow_field = [])
 * @method ConsultingServer updateActiveByClosure(\Closure $closure, array $params, array $allow_field = [])
 * @method void deleteModel(ConsultingServer $model)
 * @method void deleteById(int|array|\Closure $id, bool $force = false)
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class ConsultingServerDao
{
    use DaoTrait;

    /**
     * @var \app\common\model\ConsultingServer
     */
    private $baseModel;

    /**
     * MemberAskServerDao constructor.
     */
    public function __construct()
    {
        $this->baseModel = ConsultingServer::class;
    }

    /**
     * 咨询列表的可选服务选项
     * @return Collection
     */
    public function selectOptionsOfConsulting(): Collection
    {
        return ConsultingServer::where('deleted', '0')
            ->field(['name' => 'label', 'id' => 'value'])
            // 1自定义服务 2免费咨询 3极速咨询 4畅聊 5电话咨询
            ->orderValues('serverType', [2, 6, 3, 4, 5, 1])
            ->order('ord', 'ASC')
            ->order('id', 'DESC')
            ->select();
    }

    /**
     * 自定义服务列表
     * @param int|null $page
     * @param int|null $page_size
     * @return array
     */
    public function listServers(?int $page, ?int $page_size): array
    {
        $query = ConsultingServer::where('serverType', '1')
            ->where('deleted', '0')
            ->append(['iconImg'])
            ->order('ord', 'ASC')
            ->order('id', 'DESC')
            ->paging($page, $page_size);

        return listOutput($query, $page_size);
    }


    /**
     * 可选推荐服务列表
     * @return Collection
     */
    public function selectRecommendServers(): Collection
    {
        return ConsultingServer::whereIn('serverType', [3, 4])
            ->where('deleted', '0')
            ->append(['iconImg'])
            ->orderValues('serverType', [2, 6, 3, 4, 5, 1])
            ->order('ord', 'ASC')
            ->order('id', 'DESC')
            ->select();
    }
}
